package com.hison.controller;

import com.hison.service.ArticleService;
import com.hison.util.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName: ArticController
 * @Descripiton: TODO
 * @Author: 小郑
 * @Date： 2024/1/12 11:10
 * @Version：1.8
 **/
@RestController
@RequestMapping("/article")
@Api(value = "文章接口", description = "对文章相关操作的api接口")
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    @GetMapping("/hotArticleList")
    @ApiOperation(value = "查询热点文章", notes = "查询热点文章", produces = "application/json")
    public ResponseResult hotArticleList() {
        //查询热门文章
        return articleService.hotArticleList();
    }

    @GetMapping("/articleList")
    @ApiOperation(value = "分页查询文章接口", notes = "文章分页接口", produces = "application/json")
    public ResponseResult articleList(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                      @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                      @RequestParam(value = "categoryId", required = false) Long categoryId) {
        return articleService.articleList(pageNum, pageSize, categoryId);
    }


    @GetMapping("/{id}")
    @ApiOperation(value = "获取文章详情接口", notes = "文章详情接口", produces = "application/json")
    public  ResponseResult  getArticleDetail(@PathVariable("id") Long id){
        return  articleService.getAticleDetail(id);
    }

    @PutMapping("/updateViewCount/{id}")
    public  ResponseResult updateViewCount(@PathVariable("id") Long id){
        return articleService.updateViewCount(id);
    }

}